"""
author: liuxu
date: 2024.12.3
description:
"""
import allure
import pytest
import os
from common.logger_ctrl import mylogger
from common.ssh_command import exec_cmd
from base_public.testbase import BasePublic


@allure.feature('测试多进程程序')
@pytest.mark.high
class TestMultiprocess(BasePublic):
    def test_multithread(self, test_env):
        """
        测试单卡多线程
        :return:
        """
        # ret, output = exec_cmd(f"HIP_VISIBLE_DEVICES=0 hipprof {self.get_exe_abspath('multiprocess_multithread_multidevice_test')}", cwd=test_env)
        # 复制当前环境变量
        new_env = os.environ.copy()
        # 添加新的环境变量
        new_env['HIP_VISIBLE_DEVICES'] = '0'

        testcase = self.compile_source_code(src_file_name="multiproc_case/multithreading_singledevice.cpp")
        ret, output = exec_cmd(f"hipprof {testcase}", cwd=test_env, env=new_env)
        assert ret is True
        assert self.check_trace_output_success(output) is True

    def test_multiprocess_multidevice(self, test_env):
        """
        测试多卡多进程
        :return:
        """
        testcase = self.compile_source_code(src_file_name="multiproc_case/multiprocess_multithread_multidevice_test.cpp")
        ret, output = exec_cmd(f"hipprof {testcase}", cwd=test_env)
        assert ret is True
        assert self.check_trace_output_success(output) is True